﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using MTC.Common.Configuration;
using MTC.Common.DTO;

namespace MTC.DataAccess
{
    public static class GenderDataAccess
    {
        public static List<Gender> GetGenders()
        {
            List<Gender> listOfGender = new List<Gender>();

            Database db = DatabaseFactory.CreateDatabase(ApplicationSettings.Settings.Database.ConnectionStringName);
            if (db != null)
            {
                const string sqlCommandText = "spGender_GetAllGenders";
                using (SqlCommand sqlCommand = db.GetStoredProcCommand(sqlCommandText) as SqlCommand)
                {

                    using (SqlDataReader dataReader = db.ExecuteReader(sqlCommand) as SqlDataReader)
                    {
                        Gender entity;

                        if (dataReader != null)
                            while (dataReader.Read())
                            {
                                entity = new Gender();
                                if (!Convert.IsDBNull(dataReader["GenderId"]))
                                    entity.GenderId = Convert.ToInt32(dataReader["GenderId"]);
                                if (!Convert.IsDBNull(dataReader["Description"]))
                                    entity.Description = Convert.ToString(dataReader["Description"]);

                                listOfGender.Add(entity);
                            }
                    }
                }
            }
            return listOfGender;
            
 
        }

    
    
    }
}
